package com.cskaoyan.market.controller;

import com.cskaoyan.market.service.MarketConfigService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.MarketConfigExpressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: 付诚
 * @Date: 2024/5/9 15:11
 * @Description:
 */
@RestController
@RequestMapping("/admin/config")
public class AdminConfigController {

    @Autowired
    private MarketConfigService marketConfigService;

    @RequestMapping("/mall")

    private Object mall() {
        Map<String, String> data = marketConfigService.mall();
        return ResponseUtil.ok(data);
    }

    @PostMapping("/mall")
    private Object mallUpdate(@RequestBody Map marketSystemMap) {

        if (marketSystemMap == null) {
            return ResponseUtil.fail();
        }
        marketConfigService.mallUpdate(marketSystemMap);

        return ResponseUtil.ok();
    }

    @RequestMapping("express")
    public Object expree() {

        Map<String, String> data = marketConfigService.express();
        return ResponseUtil.ok(data);
    }


    @PostMapping("express")
    public Object expreeUpdate(@RequestBody MarketConfigExpressVo marketExpreeVo) {
        if (marketExpreeVo == null) {
            return ResponseUtil.fail();
        }
        marketConfigService.mallUpdate(marketExpreeVo);
        return ResponseUtil.ok();
    }

    @RequestMapping("order")
    public Object order() {
        Map<String, String> data = marketConfigService.order();
        return ResponseUtil.ok(data);
    }

    @PostMapping("order")
    public Object orderUpdate(@RequestBody Map marketOrderMap) {
        if (marketOrderMap == null) {
            return ResponseUtil.fail();
        }
        marketConfigService.orderUpdate(marketOrderMap);
        return ResponseUtil.ok();
    }

    @RequestMapping("wx")
    public Object wx() {
        Map<String, String> data = marketConfigService.wx();
        return ResponseUtil.ok(data);
    }

    @PostMapping("wx")
    public Object wxUpdate(@RequestBody Map<String,String> marketWxMap) {
        if (marketWxMap == null) {
            return ResponseUtil.fail();
        }
        marketConfigService.wxUpdate(marketWxMap);
        return ResponseUtil.ok();
    }
}
